<?php

class TuanController extends HBaseController
{
	//设置导航焦点
	public $active_cur = 'tuan';
	/**
	 * 团购首页,兼列表页面
	 */
	public function actionIndex()
	{
		$model = new ProTuan('search');
		$model->unsetAttributes();//清空属性
		$model->zpt_status = 2;//审核状态为通过
		$model->zpt_type = 1;//类型为团购
		$model->zpt_end_time = '>'.time();//结束时间大于当前时间
		$model->zpt_close = 1;//是否关闭1否2是3删除
		//顶级分类筛选
		if(isset($_GET['cat'])){
			$model->category_top = $_GET['cat'];
		}
		//价格区间
		if(isset($_GET['pri'])){
			$model->priceInterval = $_GET['pri'];
		}
		//排序
		if(isset($_GET['ord'])){
			$model->list_order = $_GET['ord'];
		}

		$this->render('index',array(
			'model'=>$model,	
			));
	}

	
	/**
	 * 团购详细页面
	 */
	public function actionDetail($id){
		
		$model = ProTuan::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		
		$tuanOrder = new TuanUser('search');
		$tuanOrder->unsetAttributes();//清空属性
		$tuanOrder->zpt_id = $model->zpt_id;//当前团购ID
		$tuanOrder->ztu_status = 2;//购买完成
		
		$this->render('detail',array(
				'model'=>$model,
				'tuanOrder'=>$tuanOrder,
		));
	}
	
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}